﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;

namespace MsChartRendering
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private  void DrawPieChart(int width,int height)
        {
            using (Chart chart = new Chart())
            {
                chart.Width = width;
                chart.Height = height;
                chart.RenderType = RenderType.BinaryStreaming;
                chart.Palette = ChartColorPalette.BrightPastel;
                chart.BorderWidth = 2;
                chart.IsSoftShadows = true;
                chart.ChartAreas.Add("Top");
                //  chart.ChartAreas.Add("Bottom");
                chart.Series.Add("Price");
                //chart.Series.Add("Volume");
                chart.Series["Price"].ChartArea = "Top";
                //  chart.Series["Volume"].ChartArea = "Bottom";

                chart.Series["Price"].ChartType = SeriesChartType.Pie;
                // chart.Series["Volume"].ChartType = SeriesChartType.Column;
               
                chart.Series["Price"].XValueMember = "Key";
                chart.Series["Price"].YValueMembers = "Value";
                chart.DataSource = Data.CreatDataforPieChart();
                System.Web.UI.DataVisualization.Charting.Title title = new Title("Pie chart");
                chart.Titles.Add(title);

                using (MemoryStream memStream = new MemoryStream())
                {
                    chart.SaveImage(memStream, ChartImageFormat.Jpeg);
                    Response.BinaryWrite(memStream.ToArray());
                    //    return File(memStream.ToArray(), "image/jpeg");
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
           
            DrawPieChart(600,400);
        }
    }
}